from compare import Int, Quick
import random

def generate_data(count=10):
    return [Int(random.randrange(0,count*100)) for i in range(count)]

def rank(data,key):
    lo=0
    hi=len(data)-1
    while(lo <= hi):
        mid=lo +(hi-lo)//2
        diff=key -data[mid].number
        if diff < 0:
           hi=mid -1
        elif diff > 0:
            lo=mid+1
        else:
            return (True,mid)
    else:
        return(False,lo)

import time
if __name__=="__main__":
    data=generate_data(8000)
    start_time= time.time()
    Quick().sort(data)
    exec_time=time.time()-start_time
    key=random.choice(data).number
    print(f"{data}")
    print(f"exec_time: {exec_time}")
    while True:
        key=int(input("please:"))
        if key == 0:
            break
        start_time=time.time()
        result,key =rank(data,key)
        exec_time=time.time()-start_time
        print(f"exec_time: {exec_time}")
        if result:
            print(f"success {key} {data[key]} ")
        else:
            print(f"failure {key}")
